package com.zyf.audio;

import com.alibaba.fastjson.JSONObject;
import com.zyf.audio.util.SqlUtil;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * Created by hp on 2021/10/15.
 */
public class ReceiceThread extends  Thread{
    private Socket socket;
    public ReceiceThread(Socket socket){
        this.socket = socket;
    }
    public void run(){
        OutputStream os = null;
        JSONObject job = SqlUtil.query(this.getName());
        try {
            while(true){
                os = this.socket.getOutputStream();
                os.write(job.toJSONString().getBytes());
                os.flush();
                Thread.sleep(10000);
            }
        }catch (InterruptedException e){
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (os!=null) os.close();
                if (this.socket!=null) this.socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
